After successfully completing your first exercises to make yourself familiar with R and Rstudio, listening to lengthy lectures on data types, formats, functions, and loops, it’s now time to program a little bit. Surely, we cannot cover all the lecture topics, but you should get a good feel about programming. While it can get involved, don’t worry; the first start is not that hard.
This being said, let’s start with some casual tinkering with different data types.
c() or matrix(). Data types, e.g., can be numeric, character strings, and so forth. Please also add another list in this list to create a nested one.
Ok. That’s quite a mishmash (I am so happy this word exists) of different data, right? It’s not easy to grasp which list element is of what data format and what data type. Sometimes we, therefore, have to query this information and print it out. I am sure you can build a loop for that.
numeric_vector <- c(1, 2, 3, "four"). Create an if-else loop that checks whether this vector really comprises numeric values, prints out a corresponding message if yes, and the same if it does not comprise numeric values.
is.numeric() function.
That’s nice but static. We have to repeatedly write this statement if we want to check multiple objects. Let’s write a function.
function () match the ones within the curly brackets {}.